08. Exercise: Add a DatabaseVideo Entity

It's time to make a database object called DatabaseVideo. This will be a Room Entity.

1. Create the DatabaseVideo database object. In database/DatabaseEntities, create a Room @Entity called DatabaseVideo:

@Entity
data class DatabaseVideo constructor(
        @PrimaryKey
        val url: String,
        val updated: String,
        val title: String,
        val description: String,
        val thumbnail: String)



2. Add an extension function which converts from database objects to domain objects:

fun List<DatabaseVideo>.asDomainModel(): List<Video> {
    return map {
        Video (
           url = it.url,
           title = it.title,
           description = it.description,
           updated = it.updated,
           thumbnail = it.thumbnail)
    }
}



3. Finally, in network/DataTransferObjects.kt, create an extension function that converts from data transfer objects to database objects:

fun NetworkVideoContainer.asDatabaseModel(): Array<DatabaseVideo> {
    return videos.map {
        DatabaseVideo (
           title = it.title,
           description = it.description,
           url = it.url,
           updated = it.updated,
           thumbnail = it.thumbnail)
    }.toTypedArray()
}



If you want to start at this step, you can download this exercise code from: Step.01-Exercise-Add-DatabaseVideo-Entity.

You will find plenty of //TODO comments to help you complete this exercise, and if you get stuck go back and watch the video again.

Once you’re done, you can check your solution against the solution we’ve provided here Step.01-Solution-DatabaseVideo-Entity or using this git diff

Task Description:

Check the steps below as you implement them to complete this exercise.

Task List:

Task Feedback:

Great work! Your offline cache is progressing well.

Reference documentation